import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-03
 * Time: 14:21
 */
public class Test13 {
    public static int maxSubSum(int[] num) {
        int ret = 0;
        int n = num.length;
        // 以i为结尾的子数组最大和
        int[] dp = new int[n+1];
        dp[0] = 0;
        for(int i = 1; i <= n; i++) {
            dp[i] = Math.max(dp[i-1]+num[i-1],num[i-1]);
            ret = Math.max(dp[i],ret);
        }
        return ret;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        for(int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
        }
        int ret = maxSubSum(num);
        System.out.println("最大子数组和："+ret);
    }
}
